package converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class SelectOneMenuConverter implements Converter{

	public Object getAsObject(FacesContext paramFacesContext,
			UIComponent paramUIComponent, String paramString) {
		
		if ((paramFacesContext == null) || (paramFacesContext == null)) {
			throw new NullPointerException();
		}
	
		if (paramString == null) {
		       return null;
        }
		
		if(paramString.equals("-1")){
			return "javax.faces.component.UISelectOne.INVALID";
		}
		try{
			return String.valueOf(paramString);
	    }catch (Exception e) {
	        throw new ConverterException(e);
	    }
		
	}

	public String getAsString(FacesContext paramFacesContext,
			UIComponent paramUIComponent, Object paramObject) {
		
		 if ((paramFacesContext == null) || (paramFacesContext == null)) {
			throw new NullPointerException();
	     }
	 
	     if (paramObject == null) {
	       return "";
	     }
	     
	     if(paramObject.equals("-1")){
				return "";
		 }
	 
	     if (paramObject instanceof String) {
	       return ((String)paramObject);
	     }
	     try
	     {
	       return ((String)paramObject);
	     } catch (Exception e) {
	       throw new ConverterException(e);
	     }		
	}

}
